package day15;

import java.util.*;

public class Demo {
    public static void main(String[] args) {
        String str="this is my name my name is wanxing is his birthday";
        Map<String,Integer> map=new TreeMap<>();
        for (String word:str.split(" ")){
            if (map.containsKey(word)){
                map.put(word,map.get(word)+1);
            }else {
                map.put(word,1);
            }
        }
        System.out.println(map);
        List<Map.Entry<String,Integer>> list=new ArrayList<>(map.entrySet());
        Collections.sort(list,(o1, o2) -> o2.getValue()- o1.getValue());
        System.out.println(list);
    }
}
